package com.kunyi.web.service.log.core.configuraion;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @ClassName DruidConfiguration
 * @Description 数据源配置，这里使用clickhouse
 * @Author pengjunjun
 * @Date 2024/3/6 13:48
 * @Version 1.0
 **/

@Configuration
public class DruidConfiguration {

    @Autowired
    private ClickHouseProperties clickHouseProperties ;

    @Bean
    public DataSource dataSource() {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(clickHouseProperties.getUrl());
        datasource.setDriverClassName(clickHouseProperties.getDriverClassName());
        datasource.setInitialSize(clickHouseProperties.getInitialSize());
        datasource.setMinIdle(clickHouseProperties.getMinIdle());
        datasource.setMaxActive(clickHouseProperties.getMaxActive());
        datasource.setMaxWait(clickHouseProperties.getMaxWait());
        datasource.setUsername(clickHouseProperties.getUsername());
        datasource.setPassword(clickHouseProperties.getPassword());
        return datasource;
    }
}
